<script type="text/javascript" src="__PUBLIC__/plus/fancybox/jquery.fancybox-1.3.4.js"></script>
<link href="__PUBLIC__/plus/fancybox/jquery.fancybox-1.3.4.css" type="text/css" rel="stylesheet" />
<div class="Item hr">
    <div class="current">图片管理</div>
    <div class="fr"><a href="{:U('add', array('fid' => $fid))}" class="btn">添加图片</a></div>
</div>
<form>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab">
        <thead>
            <tr height="25" align="center">
                <td width="4%">选择</td>
                <td width="20%">图片预览</td>
                <td width="20%">文字标题</td>
                <td width="20%">所属焦点图</td>
                <td width="10%">链接地址</td>
                <td width="10%">状态</td>
                <td width="10%">排序</td>
                <td width="10%">操作</td>
            </tr>
        </thead>
        <tbody>
            <volist name="list" id="img" empty="$empty">
            <tr align="center">
                <td>{:genCheckbox('id', '', $img['id'], false, 'id')}</td>
                <td><a href="{$img['imgpath']}" rel="item_group" title="{$img['title']}"><img src="{$img['imgpath']}" class="img-thumbnail" style="height:100px;" /></a></td>
                <td>{$img['title']}</td>
                <td>{$img['focus_name']}</td>
                <td><a href="{$img['url']}" title="{$img['url']}" target="_blank">{$img['url']}</a></td>
                <td>{$img['status'] == 1 ? '启用' : '禁用'}</td>
                <td><input type="text" class="input" size="3" value="{$img['sortrank']}" style="text-align:center;" /></td>
                <td><a href="{:U('edit', array('id' => $img['id']))}" class="icon-edit" title="编辑"></a> <a href="javascript:;" class="deleted icon-remove" data-url="{:U('delete')}" data-id="{$img.id}" data-title="{$img.title}" title="删除"></a> </td>
            </tr>
            </volist>
        </tbody>
        <tfoot>
        	<tr>
            	<td colspan="8">
                <label><input name="" class="chooseAll" type="checkbox"> 全选</label> <label><input name="" class="unsetAll" type="checkbox"> 反选</label>
                </td>
            </tr>
        </tfoot>
    </table>
</form>
<div class="commonBtnArea" >
    <button class="btn" id="deleted" data-url="{:U('delete', array('fid' => $fid))}">删除</button>
</div>

<script type="text/javascript">
$(function(){
	clickCheckbox();
	//单个删除
    $(".deleted").click(function(){
        var url = $(this).data("url");
        var id = $(this).data("id");
        var title = $(this).data("title");

        popup.confirm("您确定删除 <b>" + title + "</b> 图片？", '温馨提示',function(action){
            if(action == 'ok'){
                $.ajax({
					"url" : url,
					"dataType" : "JSON",
					"type" : "POST",
					"data" : {"id" : id},
					"success" : function(json){
                    if (json.status) {
                        popup.success(json.info, "删除成功", function(){
							if(json.url){
								window.location.href = json.url;
							}else{
								top.window.location.reload();
							}
						});
                    } else {
                        popup.error(json.info);
                        setTimeout(function(){
                            popup.close("asyncbox_error");
                        },2000);
                    }
                }
				});
            }
        });

        return false;
    });
	//批量删除
    $("#deleted").click(function(){
        var url = $(this).data("url");
		var isDeleted = false;
		var ids = [];
		$(".id").each(function(){
			if($(this).prop("checked")){
				isDeleted = true;
				ids.push($(this).val());
			}
		})
		if(isDeleted){
			popup.confirm("您确定批量删除图片？", '温馨提示',function(action){
				if(action == 'ok'){
					$.ajax({
						"url" : url,
						"dataType" : "JSON",
						"type" : "POST",
						"data" : {"ids" : ids, "act" : "two"},
						"success" : function(json){
						if (json.status) {
							popup.success(json.info, "删除成功", function(){
								if(json.url){
									window.location.href = json.url;
								}else{
									top.window.location.reload();
								}
							});
						} else {
							popup.error(json.info);
							setTimeout(function(){
								popup.close("asyncbox_error");
							},2000);
						}
					}
					});
				}
			});
		}
        return false;
    });
	
$("a[rel=item_group]").fancybox({
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'titlePosition' 	: 'over',
	'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
	}
});
});
</script>